<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;

class User extends Controller
{
	//渲染会员列表
    public function index(){
    	if(!empty($_GET['userPhone'])){
    		$phone = $_GET['userPhone'];
    		$num = count(Db::name('userinfo')
    		-> where('user_name',$phone)
    		-> select());
    		$result = Db::name('userinfo')
    		-> where('user_name',$phone)
    		-> paginate(1);
    	}else{
    		$num = count(Db::name('userinfo') 
    		-> select());
    		$result = Db::name('userinfo') 
    		-> order('id desc') 
    		->paginate(5);
    	}
    	
    	$this -> assign("userarr",$result);
    	$this -> assign("num",$num);
    	
        return $this -> fetch('user/member-list');
    } 
    
    //渲染会员订阅条件列表
   	public function collect(){
   		if(!empty($_GET['userPhone'])){
   			$phone = $_GET['userPhone'];   			
   			$num = count(Db::name('collectinfo')
			-> alias('a')
			-> join('userinfo b','a.user_id = b.id')
			-> where('b.user_name',$phone)
			-> select());
   			$result = Db::table('collectinfo')
			-> alias('a')
			-> join('userinfo b','a.user_id = b.id')
			-> where('b.user_name',$phone)
			-> order('a.collect_id desc') 
			-> paginate(5);
   			
   		}else{
   			$num = count(Db::name('collectinfo') -> select());
	    	$result = Db::table('collectinfo')
			-> alias('a')
			-> join('userinfo b','a.user_id = b.id')
			-> order('a.collect_id desc') 
			-> paginate(5);
   		}   		
    	$this -> assign("collectarr",$result);
    	$this -> assign("num",$num);
   		return $this -> fetch('user/collect-list');
   	}
   	
   	//渲染会员收藏列表
   	public function take(){
   		if(!empty($_GET['userPhone'])){
   			$phone = $_GET['userPhone'];
   			$num = count(Db::table('takeinfo')
			-> alias('a')
			-> join('userinfo b','a.user_id = b.id')
			-> where('b.user_name',$phone)
			-> select());
   			$result = Db::table('takeinfo')
			-> alias('a')
			-> join('userinfo b','a.user_id = b.id')
			-> where('b.user_name',$phone)
			->order('a.take_id desc')
			-> paginate(5);  			
   		}else{
   			$num = count(Db::name('takeinfo') -> select());
	    	$result = Db::table('takeinfo')
			->alias('a')
			->join('userinfo b','a.user_id = b.id')
			->order('a.take_id desc')
			->paginate(5);
   		}
   		
    	$this -> assign("takearr",$result);
    	$this -> assign("num",$num);
   		
   		return $this -> fetch('user/take-list');
   	}
   	
   	//渲染会员评价列表
   	public function assess(){
   		if(!empty($_GET['userPhone'])){
   			$phone = $_GET['userPhone'];
   			$num = count( Db::table('evaluateinfo')
			->alias('a')
			->join('userinfo b','a.user_id = b.id')
			->join('houseinfo c','a.house_id = c.id')
			-> where('b.user_name',$phone)
			-> select());
   			$result = Db::table('evaluateinfo')
			->alias('a')
			->join('userinfo b','a.user_id = b.id')
			->join('houseinfo c','a.house_id = c.id')
			-> where('b.user_name',$phone)
			->order('a.evaluate_id desc')
			->paginate(5);   			
   		}else{
   			$num = count(Db::name('evaluateinfo') -> select());
	    	$result = Db::table('evaluateinfo')
			->alias('a')
			->join('userinfo b','a.user_id = b.id')
			->join('houseinfo c','a.house_id = c.id')
			->order('a.evaluate_id desc')
			->paginate(5);
   		}   		
   		
    	$this -> assign("assessarr",$result);
    	$this -> assign("num",$num);
   		
   		return $this -> fetch('user/assess-list');
   	}
}

?>